Understanding :link vs :visited Pseudo-Classes in CSS
In CSS, :link and :visited are pseudo-classes used to style anchor (<a>) elements depending on whether the link has been visited by the user.
:link – Targets all unvisited links. These are links the user has not clicked on yet.
:visited – Targets links that the user has already visited. Browsers restrict the styles that can be applied to protect user privacy.
Use :link and :visited to visually differentiate unvisited and visited links for better navigation experience.
In this example, links the user has not visited appear blue (:link), and links that have been visited appear purple (:visited). Hovering over any link changes its color and adds an underline.
Always use :link and :visited together to provide clear navigation cues.
Avoid using styles that violate privacy restrictions; only certain properties like color can be applied to :visited.
Combine with :hover and :active for consistent interactive feedback.
Test link styling across browsers as handling of visited links may vary.
You're building a simple navigation bar and notice that all links look the same—even after clicking them. How would you fix it using :link and :visited?
A junior designer says they want visited links to turn red and bold. What’s the problem with that request, and how would you explain it?
What happens if you write a CSS rule for :visited but forget to define :link? Do the links still look different after being clicked?
Our users report that some links in the footer appear dim after clicking, but others don’t. You’ve checked the CSS—:visited is set, but it’s not working. What could be going wrong?
We’re building a documentation site with hundreds of internal links. Some teams are using :visited to indicate ‘read’ content, but accessibility audits are flagging it. How would you debug and fix this?
A feature flag turns on a custom theme that changes link colors. After the update, users say they can’t tell which links they’ve visited. What’s the most likely cause, and how do you verify it?
We’re designing a global navigation component used across 50+ micro-frontends. How do you ensure consistent :link and :visited behavior without breaking privacy restrictions or causing layout shifts?
Our analytics show users are clicking the same links repeatedly—could :visited styling be contributing to confusion? How would you redesign the feedback system to improve usability without violating browser security policies?
A legacy CSS file uses :visited to change background images. It’s causing performance issues and layout thrashing. How would you refactor this without losing the visual feedback users rely on?
We’re migrating from a monolith to a component library, and legacy code relies on :visited for user progress tracking. How do you deprecate this safely without breaking user expectations or introducing privacy risks?
Our design system allows teams to customize link states. How do you enforce a policy around :visited styling that balances brand flexibility, accessibility, and browser security constraints across 200+ products?
A competitor uses :visited to track user behavior via CSS-based telemetry. How would you architect a privacy-compliant alternative that still provides engagement insights without exposing browsing history?